package com.example.tests.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import factories.MyPageFactory;

public class ProfilePage extends MainTemplate {
	@FindBy(name = "username")
	private WebElement username;
	@FindBy(name = "password")
	private WebElement password;
	@FindBy(name = "password2")
	private WebElement password2;
	@FindBy(name = "submit")
	private WebElement submit;
	@FindBy(name = "email")
	private WebElement email;
	@FindBy(xpath = "//select/option[ @selected=\"\" ] ")
	private WebElement role;

    
	public UserManagementPage setPassword(String passwd) {
		 password.clear();
		 password.sendKeys(passwd);
		 password2.clear();
		 password2.sendKeys(passwd);
		 submit.click();
		 return MyPageFactory.getPage(driver, UserManagementPage.class);
	}
	public boolean isRoleMatches(String UserRole) {
		 return role.getText().matches(UserRole);
	}
	public boolean isEmailMatches(String mail) {
		 return email.getAttribute("value").matches(mail);
	}
	public boolean isUsernameMatches(String name) {
		 return username.getAttribute("value").matches(name);
	}
	public void goHere() {
		profileLink.click();
	}
	public boolean isOnThisPage() {
		return ( 0 < driver.findElements(By.id("content")).size() ) 
					&&  0 < driver.findElements(By.name("email")).size() ;
	}
	
	@Override
	public void tryToOpen() {
		MyPageFactory.getPage(driver, LoginPage.class)
			.loginSuccesfullAs("admin", "admin")
			.goProfilePage();
	}
}
